//
//  GHUtils.m
//  GodHorses
//
//  Created by Mac on 2017/11/14.
//  Copyright © 2017年 stoneobs@icloud.com. All rights reserved.
//

#import "TMUtils.h"

@implementation TMUtils
+ (void)netWorkMonitorinCanUseWithHandle:(void (^)())handle{
    
    AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
    [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        if (status == AFNetworkReachabilityStatusReachableViaWWAN || status == AFNetworkReachabilityStatusReachableViaWiFi) {
            if (handle) {
                handle();
            }
        }
    }];
    [manager startMonitoring];
}
+ (UIView*)headerViewWithTitle:(NSString*)title{
    UIView * sectionHeader = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 44)];
    sectionHeader.backgroundColor = [UIColor whiteColor];
    STButton * line = [[STButton alloc] initWithFrame:CGRectMake(15, 0, 8, 8)
                                                title:nil
                                           titleColor:nil
                                            titleFont:0
                                         cornerRadius:4
                                      backgroundColor:TM_redColor
                                      backgroundImage:nil
                                                image:nil];
    line.centerY = 22;
    [sectionHeader addSubview:line];
    STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(line.right + 10, 0, 200, 44)
                                                     text:title
                                                textColor:TM_firstTextColor
                                                     font:14
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    
    [sectionHeader addSubview:titleLable];
    return sectionHeader;
}
+ (UIView*)headerViewWithTitle:(NSString*)title moreButtonAction:(void(^)(UIButton*sender))handle{
    UIView * view = [TMUtils headerViewWithTitle:title];
    STButton * moreButton = [[STButton alloc] initWithFrame:CGRectMake(0, 5, 65, 34)
                                                      title:@"更多 >"
                                                 titleColor:[UIColor whiteColor]
                                                  titleFont:10
                                               cornerRadius:0
                                            backgroundColor:nil
                                            backgroundImage:[UIImage imageNamed:@"双击替换元素1"]
                                                      image:nil];
    [view addSubview:moreButton];
    moreButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    moreButton.right = UIScreenWidth - 15;
    [moreButton setClicAction:^(UIButton *sender) {
        if (handle) {
            handle(sender);
        }
    }];
    return view;
}
+ (UINavigationBar *)navigationBar{
    UINavigationController* nav = (id)[UIApplication sharedApplication].keyWindow.rootViewController.childViewControllers.firstObject;
    return nav.navigationBar;
}
+  (UITabBar *)tabbar{
    UITabBarController* tab = (id)[UIApplication sharedApplication].keyWindow.rootViewController;
    return tab.tabBar;
}
+ (CGFloat)navgationBarBootom{
    if (KIsiPhoneX) {
        return 88;
    }
    return 64;
}
+ (CGFloat)tabBarTop{
    if (KIsiPhoneX) {
        return (UIScreenHeight - 83);
    }
    return (UIScreenHeight - 49);
}
+ (void)debugSimulationNetWorkWithHadle:(void(^)(NSInteger))handle{
    [SVProgressHUD showWithStatus:@"请稍后"];
    NSInteger num = 1;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(num * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [SVProgressHUD dismiss];
        if (handle) {
            handle(num);
        }
    });
}
+ (STButton *)deflutNextButton{
    STButton * buyButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 49)
                                                     title:@"下一步"
                                                titleColor:FirstTextColor
                                                 titleFont:18
                                              cornerRadius:0
                                           backgroundColor:nil
                                           backgroundImage:[UIImage imageNamed:@"确认bg"]
                                                     image:nil];
    buyButton.top = [TMUtils tabBarTop];
    buyButton.contentHorizontalAlignment = UIControlContentVerticalAlignmentCenter;
    return buyButton;
}
+ (STButton *)deflutAddImageButtonWithActionHandle:(BOOL (^)(UIButton *))handle{
    STButton * confimButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, 100 , 75)
                                                        title:@""
                                                   titleColor:[UIColor whiteColor]
                                                    titleFont:18
                                                 cornerRadius:10
                                              backgroundColor:[UIColor whiteColor]
                                              backgroundImage:nil
                                                        image:[UIImage imageNamed:@"icon_添加图片"]];
    [confimButton setClicAction:^(UIButton *sender) {
       //移除所有view
        if (handle) {
           BOOL remove =  handle(sender);
            if (remove) {
                UIView * view = [sender viewWithTag:10000];
                [view removeFromSuperview];
            }
        }
    }];
    confimButton.centerX = UIScreenWidth / 2;
    confimButton.imageEdgeInsets = UIEdgeInsetsMake(-10, 0, 0, 0 );
    confimButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;

    STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(0, 0, confimButton.width, 20)
                                                     text:@"点击添加图片"
                                                textColor:ThirdTextColor
                                                     font:14
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentCenter];
    titleLable.bottom = confimButton.height - 5;
    titleLable.tag = 10000;
    [confimButton addSubview:titleLable];

    [confimButton st_setBorderWith:0.5 borderColor:TM_lineColor cornerRadius:0];
    return confimButton;
}
+ (STButton *)deflutMoreButton{
    STButton * moreButton = [[STButton alloc] initWithFrame:CGRectMake(0, 5, 65, 34)
                                                      title:@"更多 >"
                                                 titleColor:[UIColor whiteColor]
                                                  titleFont:10
                                               cornerRadius:0
                                            backgroundColor:nil
                                            backgroundImage:[UIImage imageNamed:@"双击替换元素1"]
                                                      image:nil];
    moreButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    moreButton.right = UIScreenWidth - 15;
    return moreButton;
}
@end
